<?php
namespace Rate\Controller;
use Todo\Controller\CurdController;
use Todo\Service\MessageService;

class ProjectController extends CurdController {

    /**
     * 给参评参评人发送消息
     */
    public function notice(){
        $id = I('get.project_id/d');
        if(!$id) $this->error("非法请求，请选择项目！");

        $this->_loadModel();
        $info = $this->_model->keyFind($id);
        if(!$info) $this->error("非法请求，您选择的项目不存在或已结束！");

        $list = D('Todo/Rate/User')->where(array('project_id'=>$id, 'type'=>'2'))->select();

        $title = '评测邀请提醒';
        $content = '系统安排您参与《'.$info['title'].'》项目的评测，请及时登录系统参与！系统地址:'. full_url();
        if(!MessageService::getInstance()->pushMessage($title, $content, '', 1, array_column($list, 'user_id'))){
            $this->error(MessageService::getInstance()->getError());
        }else{
            $this->success('发送消息成功!');
        }
    }

    /**
     * 计算
     */
    public function count(){
        $id = I('get.project_id/d');
        if(!$id) $this->error("非法请求，请选择项目！");

        $this->_loadModel();
        if(!$this->_model->countScore($id)) $this->error("发生错误:". $this->_model->getError());
        $this->success("计算成功!");
    }
}